/**
 * Created by Administrator on 2017/6/30 0030.
 */
"use strict";

angular.module('app.yksensor').controller('YKLogCtrl', function ($scope, sensorHttpS,$http,$cookieStore) {

    //配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 5,
        totalItems: 20,
        perPageOptions: [10, 20, 30, 50, 1000],

        onChange: function () {
        }
    };
    
    $scope.sends = function () {

        var timefrom = $('#startdate').val();
        var timeto = $('#finishdate').val();
        if(timefrom == "" && timeto == ""){
            $scope.paginationConf.time = "";
        }else{
            $scope.paginationConf.time = $('#startdate').val()+","+$('#finishdate').val();
        }
        $scope.paginationConf.info_name = $scope.paginationConf.info_name == undefined ? "" :$scope.paginationConf.info_name;

        // $http.get(baseurls+"/list_nopage/logfile?info_name="+$scope.paginationConf.info_name+"&time="+$scope.paginationConf.time).then(function(res){
        //     // console.log(res.data);
        //     if(res.data.ret == 1){
        //         $scope.datas = res.data.info;
        //         $scope.paginationConf.totalItems = res.data.info.length;
        //     }
        // })
        $http.post(baseurls+"/list/select/logfile?info_name="+$scope.paginationConf.info_name+"&time="+$scope.paginationConf.time, $scope.paginationConf).then(function(res){
            // console.log(res.data)
            if(res.data.ret == 1){
                $scope.datas = res.data.rows;
                $scope.paginationConf.totalItems = res.data.records;
            }
            
        })
    // console.log($scope.paginationConf);
    }
    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',$scope.sends);

    $scope.exportData = function () {

        var blob = new Blob(["\ufeff" + document.getElementById('exportable').innerHTML], {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
        });

        saveAs(blob, "Logfile.xls");
    };


});

